﻿Imports HMSLibrary
Imports HMSDataLayer
Imports System.Collections.ObjectModel

Public Class PatientProblemsWindow

    Public Property ProblemList As ObservableCollection(Of PatientProblem)

    Private Sub MasterWindow_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded
        ProblemList = New ObservableCollection(Of PatientProblem)
        AddNew()
    End Sub

    Private Sub MainWindow_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Input.MouseButtonEventArgs) Handles Me.MouseDown
        DragMove()
    End Sub

    Private Sub CloseButton_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles CloseButton.Click
        Me.Close()
    End Sub

    Private Sub MinimizeButton_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles MinimizeButton.Click
        Me.WindowState = Windows.WindowState.Minimized
    End Sub

    Public Sub AddNew()
        ProblemCategoryComboBox.SelectedIndex = -1
        ProblemComboBox.SelectedIndex = -1
        PeriodComboBox.SelectedIndex = -1
        ProblemTimingComboBox.SelectedIndex = -1
        ProblemDurationComboBox.SelectedIndex = -1
        ProblemLocationComboBox.SelectedIndex = -1
        ProblemSeverityComboBox.SelectedIndex = -1
        RemarksTextBox.Text = String.Empty

        Dim dataProvider As New MasterDataLayer()
        Dim lst As List(Of Lookups)

        lst = dataProvider.GetLookupList(LookupTypes.ProblemCategory)
        ProblemCategoryComboBox.ItemsSource = lst

        lst = dataProvider.GetLookupList(LookupTypes.Periods)
        PeriodComboBox.ItemsSource = lst

        lst = dataProvider.GetLookupList(LookupTypes.ProblemTiming)
        ProblemTimingComboBox.ItemsSource = lst

        lst = dataProvider.GetLookupList(LookupTypes.ProblemDuration)
        ProblemDurationComboBox.ItemsSource = lst

        lst = dataProvider.GetLookupList(LookupTypes.ProblemLocation)
        ProblemLocationComboBox.ItemsSource = lst

        lst = dataProvider.GetLookupList(LookupTypes.Severity)
        ProblemSeverityComboBox.ItemsSource = lst
        ProblemDataGrid.ItemsSource = ProblemList
    End Sub

    Private Sub AddNewProblemButton_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles AddNewProblemButton.Click
        Dim win As New MasterWindow
        win.FormType = HMSLibrary.FormsList.Problems
        win.ShowDialog()
    End Sub

    Private Sub AddProblemsButton_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles AddProblemsButton.Click
        Dim pro As New PatientProblem
        pro.reportedDateTime = Date.Now
        pro.comments = RemarksTextBox.Text.Trim
        pro.problemDurationName = PeriodComboBox.Text.Trim
        pro.problemDuration = PeriodComboBox.SelectedValue
        pro.period = Val(PeriodTextBox.Text)
        pro.problemName = ProblemComboBox.Text.Trim
        pro.problem = ProblemComboBox.SelectedValue
        pro.problemLocationName = ProblemLocationComboBox.Text.Trim
        pro.problemLocation = ProblemLocationComboBox.SelectedValue
        pro.problemPeriodName = PeriodComboBox.Text.Trim
        pro.problemPeriod = PeriodComboBox.SelectedValue
        pro.problemTimingName = ProblemTimingComboBox.Text.Trim
        pro.problemTiming = ProblemTimingComboBox.SelectedValue
        pro.severityName = ProblemSeverityComboBox.Text.Trim
        pro.severity = ProblemSeverityComboBox.SelectedValue
        ProblemList.Add(pro)
    End Sub

    Private Sub CancelButton_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles CancelButton.Click
        ProblemList = Nothing
        Me.Close()
    End Sub

    Private Sub OKButton_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles OKButton.Click
        Me.Close()
    End Sub

    Private Sub ProblemCategoryComboBox_SelectionChanged(ByVal sender As Object, ByVal e As System.Windows.Controls.SelectionChangedEventArgs) Handles ProblemCategoryComboBox.SelectionChanged
        If ProblemCategoryComboBox.SelectedItem Is Nothing Then Exit Sub
        Dim dataProvider As New MasterDataLayer()
        Dim lst As List(Of Problems)

        lst = dataProvider.GetProblemsCategoryWiseList(e.AddedItems(0).ID)
        ProblemComboBox.ItemsSource = lst
    End Sub
End Class
